
package JET.physics.bodies;

import JET.Events.BodyEvent;
import JET.Events.BodyEventListener;
import JET.Events.BodyEventNotifier;
import JET.geom.Vec2d;
import JET.physics.Border;
import JET.physics.BoundingArea;
import java.util.ArrayList;

/**
 *
 * @author 057Ry
 */
public abstract class Body implements BodyEventNotifier {


    public enum OwnerType {
        Engine,
        SceneItem,
        SpringBody
    }

    protected ArrayList<BodyEventListener> bodyListeners;
    protected boolean notifyBodyEvents;
    protected OwnerType ownerType = OwnerType.Engine;

    public Body() {
        bodyListeners = new ArrayList<BodyEventListener>();
        notifyBodyEvents = true;
    }

    public OwnerType getOwnerType() { return ownerType; }
    public void setOwnerType(OwnerType t) { ownerType = t; }

    public abstract void zeroForces();
    public abstract void accumulateExternalForces(Vec2d a);
    public abstract void accumulateInternatForces();
    
    ////////////////////////////////////////////////////////////////////////////
    //                          BODY EVENT NOTIFIER                           //
    ////////////////////////////////////////////////////////////////////////////

    public void addBodyEventListener(BodyEventListener listener) {
        bodyListeners.add(listener);
    }

    public void removeBodyEventListener(BodyEventListener listener) {
        bodyListeners.remove(listener);
    }

    public void removeAll() {
        bodyListeners.clear();
    }

    public void notifyCollisionDetected(BodyEvent evt) {
        for(BodyEventListener listener : bodyListeners)
            listener.collisionDetected(evt);
    }

    public void notifyCollisionFinished(BodyEvent evt) {
        for(BodyEventListener listener : bodyListeners)
            listener.collisionFinished(evt);
    }

    public abstract String getName();
    public abstract Border getBorder();
    public abstract BoundingArea getBoundingArea();
    public abstract void updateBoundingArea();
}